import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";

function useAuth() {
  let nav = useNavigate();
  let token = localStorage.getItem("token");
  let [isLogin, setLogin] = useState(false);
  useEffect(() => {
    if (token) {
      setLogin(true);
    } else {
      setLogin(false);
      nav("/login");
    }
  });
  return { isLogin: isLogin };
}

export default useAuth;